<template>
	<view>
		<view class="m-search">
			<image src="@/static/shop/icon-search.png" mode=""></image>
			<input type="text" @confirm="confirmFun" v-model="params.keyword" :focus="true" placeholder="输入关键字搜索" placeholder-style="color:#ADAAA5;font-size:24rpx;">
		</view>
		
		<view class="m-h3">
			<text>搜索结果</text>
		</view>
		<view class="m-list">
			<view class="m-item" v-for="(item,index) in list" :key="index" @click="to_link('/pages2/shop-detail/shop-detail?id='+item.inventoryId)">
				<view class="m-item-image">
					<image :src="item.img" mode="aspectFill"></image>
				</view>
				<view class="m-item-title u-line-2">
					<text>{{item.title}}</text>
				</view>
				<view class="m-item-bottom">
					<text class="m-item-left">{{item.price_sale}}</text>
					<view class="m-item-right">
						<image src="@/static/shop/shop-goods-cart.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<block v-if="loading == 'noMore' && list.length == 0">
		<view class="m-empty" >
			<image src="../static/shop/shop-search-empty.png" mode=""></image>
			<text>暂无结果，换个关键词试试</text>
		</view>
			<view class="m-h3">
				<text>猜你喜欢</text>
			</view>
			<view class="m-list">
				<view class="m-item" v-for="(item,index) in goodsList" :key="index" @click="to_link('/pages2/shop-detail/shop-detail?id='+item.inventoryId)">
					<view class="m-item-image">
						<image :src="item.img" mode="aspectFill"></image>
					</view>
					<view class="m-item-title u-line-2">
						<text>{{item.title}}</text>
					</view>
					<view class="m-item-bottom">
						<text class="m-item-left">{{item.price_sale}}</text>
						<view class="m-item-right">
							<image src="@/static/shop/shop-goods-cart.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</block>
		<uni-load-more v-else :status="loading"></uni-load-more>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				loading: 'loading',
				params: {
					page: 1,
					pagenum: 10,
					channel_id:'',
					keyword:''
				},
				list: [],
				
				goodsList:[],
			}
		},
		onReachBottom() {
			if(this.loading == 'noMore' || this.loading == 'loading') return false;
			this.getListFun() 
		},
		onLoad(opt) {
			this.params.keyword = opt.keyword || ''
			this.getListFun()
			this.getGoodsFun()
		},
		methods: {		
			confirmFun(){
				this.params.page = 1
				this.list = []
				this.getListFun()
			},
			getListFun(){
				this.loading = 'loading'
				let params = this.params
				this.$http.getJson('product_plist',params).then(res=>{
					if(res.code == 1){
						let list = res.data || []
						let len = list.length
						if(len > 0){
							this.list = this.list.concat(list)
						}
						if(len == params.pagenum){
							params.page += 1
							this.loading = 'more'
						}else{
							this.loading = 'noMore'
						}
					}
				})
			},
			getGoodsFun(){
				this.$http.getJson('product_plist',{page:1,pagenum:10}).then(res=>{
					if(res.code == 1){
						let list = res.data || []
						this.goodsList = list
					}
				})
			},
		}
	}
</script>

<style lang="scss">
.m-search{
	display: flex;
	align-items: center;
	width: 710rpx;
	height: 60rpx;
	background: #F6F6F6;
	border-radius: 34rpx 34rpx 34rpx 34rpx;
	margin-left: 20rpx;
	margin-top: 20rpx;
	padding: 0 30rpx;
	image{
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}
	input{
		flex: 1;
		height: 100%;
		font-size: 26rpx;
		color: #000;
	}
}

.m-h3{
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 32rpx;
	color: #34302D;
	font-weight: 600;
	padding: 40rpx 20rpx 30rpx;
	.m-del{
		width: 30rpx;
		height: 30rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
}
.m-empty{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
	font-size: 26rpx;
	color: #ADAAA5;
	padding-top: 30rpx;
	padding-bottom: 50rpx;
	image{
		width: 320rpx;
		height: 260rpx;
		margin-bottom: 30rpx;
	}
}
.m-list{
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	padding: 0rpx 25rpx 0;
	.m-item{
		width: 340rpx;
		.m-item-image{
			width: 340rpx;
			height: 340rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.m-item-title{
			margin-top: 20rpx;
			height: 80rpx;
			line-height: 40rpx;
			font-size: 28rpx;
			color: #34302D;
		}
		.m-item-bottom{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-top: 20rpx;
			padding-bottom: 48rpx;
			.m-item-left{
				font-size: 40rpx;
				color: #DE2C38;
				&::after{
					content: '积分';
					font-size: 24rpx;
					color: #76706B;
					margin-left: 5rpx;
				}
			}
			.m-item-right{
				width: 44rpx;
				height: 44rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
}
</style>
